//
//  YKBusinessViewController.m
//  YunKang
//
//  Created by leoking870 on 2017/9/24.
//  Copyright © 2017年 leoking870. All rights reserved.
//

#import "YKBusinessViewController.h"
#import "YKClientDataManageController.h"
#import <TFImageButton.h>
#import "YKClientVisitManageController.h"
#import "YKClientOrderManageController.h"
#import "YKClientDrugPriceManageController.h"
#import "YKClientExchangeManagerController.h"
#import "YKPerformanceExchangeViewController.h"
#import "YKClientNeedsViewController.h"

@interface ShadowView:UIView
@property(nonatomic, strong)CALayer *shadowLayer;
@end


@implementation ShadowView
- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        //////// shadow /////////
        
        
        //////// cornerRadius /////////
        self.layer.cornerRadius = 5;
//        self.layer.masksToBounds = YES;
        self.layer.shouldRasterize = YES;
        self.layer.rasterizationScale = [UIScreen mainScreen].scale;
        
        
    }
    return self;
}

- (void)layoutSubviews {
    [super layoutSubviews];
    if (!self.shadowLayer) {
        CALayer *shadowLayer = [CALayer layer];
        self.shadowLayer = shadowLayer;
        shadowLayer.frame = self.layer.frame;
        
        shadowLayer.shadowColor = [UIColor lightGrayColor].CGColor;//shadowColor阴影颜色
        shadowLayer.shadowOffset = CGSizeMake(-1, -1);//shadowOffset阴影偏移，默认(0, -3),这个跟shadowRadius配合使用
        shadowLayer.shadowOpacity = .3;//0.8;//阴影透明度，默认0
        shadowLayer.shadowRadius = 2;//8;//阴影半径，默认3
        self.layer.shadowColor = [UIColor lightGrayColor].CGColor;
        self.layer.shadowOffset = CGSizeMake(1, 1);
        self.layer.shadowOpacity = .3;
        self.layer.shadowRadius = 2;
        //路径阴影
        UIBezierPath *path = [UIBezierPath bezierPath];
        
        float width = shadowLayer.bounds.size.width;
        float height = shadowLayer.bounds.size.height;
        float x = shadowLayer.bounds.origin.x;
        float y = shadowLayer.bounds.origin.y;
        
        CGPoint topLeft      = shadowLayer.bounds.origin;
        CGPoint topRight     = CGPointMake(x + width, y);
        CGPoint bottomRight  = CGPointMake(x + width, y + height);
        CGPoint bottomLeft   = CGPointMake(x, y + height);
        
        CGFloat offset = -1.f;
        [path moveToPoint:CGPointMake(topLeft.x - offset, topLeft.y + 5)];
        [path addArcWithCenter:CGPointMake(topLeft.x + 5, topLeft.y + 5) radius:(5 + offset) startAngle:M_PI endAngle:M_PI_2 * 3 clockwise:YES];
        [path addLineToPoint:CGPointMake(topRight.x - 5, topRight.y - offset)];
        [path addArcWithCenter:CGPointMake(topRight.x - 5, topRight.y + 5) radius:(5 + offset) startAngle:M_PI_2 * 3 endAngle:M_PI * 2 clockwise:YES];
        [path addLineToPoint:CGPointMake(bottomRight.x + offset, bottomRight.y - 5)];
        [path addArcWithCenter:CGPointMake(bottomRight.x - 5, bottomRight.y - 5) radius:(5 + offset) startAngle:0 endAngle:M_PI_2 clockwise:YES];
        [path addLineToPoint:CGPointMake(bottomLeft.x + 5, bottomLeft.y + offset)];
        [path addArcWithCenter:CGPointMake(bottomLeft.x + 5, bottomLeft.y - 5) radius:(5 + offset) startAngle:M_PI_2 endAngle:M_PI clockwise:YES];
        [path addLineToPoint:CGPointMake(topLeft.x - offset, topLeft.y + 5)];
        
        //设置阴影路径
        shadowLayer.shadowPath = path.CGPath;
        self.shadowLayer.frame = self.layer.frame;
        [self.superview.layer insertSublayer:shadowLayer below:self.layer];
    }
    
}

@end

@interface YKBusinessViewController ()

@end

@implementation YKBusinessViewController

- (void)loadView {
    self.view = [[UIScrollView alloc]init];
}

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.edgesForExtendedLayout = UIRectEdgeNone;
    
    UIImageView* logo = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"index_header_logo"]];
    [logo sizeToFit];
    self.navigationItem.titleView = logo;
    
    UIImageView* topBannerImageView = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"yk_index_banner_b"]];
    [self.view addSubview:topBannerImageView];
    [topBannerImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.top.trailing.equalTo(self.view);
        make.width.equalTo(self.view.mas_width);
    }];
    
    
    ShadowView *contentView = [[ShadowView alloc]init];
    contentView.backgroundColor = [UIColor whiteColor];
    [self.view addSubview:contentView];
    [contentView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.equalTo(self.view.mas_leadingMargin);
        make.top.equalTo(topBannerImageView.mas_bottom).offset(-8);
        make.trailing.equalTo(self.view.mas_trailingMargin);
        make.bottom.equalTo(self.view.mas_bottom).offset(8);
    }];
    
   
    
    NSMutableArray* images = [NSMutableArray arrayWithCapacity:6];//
    NSArray* titles = @[@"客户订单管理",@"协议价格管理",@"客户需求管理",@"客户资料管理",@"积分兑换审批",@"客户拜访管理"];
    for (int i =1; i <= 6; ++i) {
        NSString* imageName = [NSString stringWithFormat:@"yk_index_menu_0%zd", i];
        UIImage *image = [UIImage imageNamed:imageName];
        TFImageButton* imageView = [TFImageButton imageButtonWithTitle:titles[i-1] image:image imagePosition:TFImageButtonImagePositionTop];
        
        [imageView setTitleColor:[UIColor tf_colorWithHexString:@"#8ec21f"] forState:UIControlStateNormal];
        [imageView setTitleImageOffset:16.0f];
        [imageView setContentEdgeInsets:UIEdgeInsetsMake(15, 0, 15, 0)];
        imageView.titleLabel.font = [UIFont systemFontOfSize:16];
        [images addObject:imageView];
        imageView.tag = i;
        [imageView addTarget:self action:@selector(onButtonTapped:) forControlEvents:UIControlEventTouchUpInside];
        [contentView addSubview:imageView];
    }
    [images mas_alignHorizontallyWithLineNumber:2 leadSpace:0 space:.5f trailSpace:0 topTo:contentView.mas_top topSpace:0 bottomTo:contentView.mas_bottom bottomSpace:0 verticalSpace:.5f separatorColor:[UIColor tf_colorWithHexString:@"#e8e8e8"] separatorWidth:.5f];
    
}

- (void)onButtonTapped:(id)sender {
    TFImageButton *button = sender;
    switch (button.tag) {
        case 1:
        {
            YKClientOrderManageController *vc = [[YKClientOrderManageController alloc]init];
            vc.hidesBottomBarWhenPushed = YES;
            [self.navigationController pushViewController:vc animated:YES];
            
        }
            break;
        case 2:
        {
            YKClientDrugPriceManageController *vc = [[YKClientDrugPriceManageController alloc]init];
            vc.hidesBottomBarWhenPushed = YES;
            [self.navigationController pushViewController:vc animated:YES];
            
        }
            break;
        case 3:
        {
//            YKPerformanceExchangeViewController *vc = [[YKPerformanceExchangeViewController alloc]init];
            YKClientNeedsViewController *vc = [[YKClientNeedsViewController alloc]init];
            vc.hidesBottomBarWhenPushed = YES;
            [self.navigationController pushViewController:vc animated:YES];
        }
            break;
        case 4:
        {
            YKClientDataManageController *vc = [[YKClientDataManageController alloc]init];
            vc.hidesBottomBarWhenPushed = YES;
            [self.navigationController pushViewController:vc animated:YES];
            
        }
            break;
        case 5:
        {
            YKClientExchangeManagerController *vc = [[YKClientExchangeManagerController alloc]init];
            vc.hidesBottomBarWhenPushed = YES;
            [self.navigationController pushViewController:vc animated:YES];
        }
            break;
        case 6:
        {
            YKClientVisitManageController *vc = [[YKClientVisitManageController alloc]init];
            vc.hidesBottomBarWhenPushed = YES;
            [self.navigationController pushViewController:vc animated:YES];
        }
            break;
        default:
            break;
    }
}


@end



